namespace QMVnSoft.Lists
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormDmTsBpEditor : FormListEditor
    {
        private DataGridViewTextBoxColumn Column1;
        private DataGridViewTextBoxColumn Column2;
        private DataGridViewTextBoxColumn Column3;
        private DataGridViewTextBoxColumn Column4;
        private IContainer components;
        private GridControl grdDetail;
        private int ii_RowIndex = -1;
        private LabelControl lblMa_Bp;
        private LabelControl lblNgay_Ps;
        private LabelControl lblSo_Thang;
        private LabelControl lblTk_No;
        private DataRow oDetailRow;
        private DmTsDataAccess oMethod = new DmTsDataAccess();
        private TextSearch txtMa_Bp;
        public TextDate txtNgay_Ps;
        private TextNumeric txtSo_Thang;
        private TextControl txtTen_Bp;
        private TextControl txtTen_Tk_No;
        private TextSearch txtTk_No;

        public FormDmTsBpEditor()
        {
            this.InitializeComponent();
            this.grdDetail.AutoGenerateColumns = false;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void grdDetail_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (((this.grdDetail.Rows.Count > 0) && (this.ii_RowIndex != e.RowIndex)) && ((this.grdDetail.CurrentRow != null) && (this.grdDetail.CurrentRow.DataBoundItem != null)))
            {
                this.ii_RowIndex = e.RowIndex;
                this.oDetailRow = ((DataRowView) this.grdDetail.CurrentRow.DataBoundItem).Row;
                this.OnShowObjects();
            }
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormDmTsBpEditor));
            this.grdDetail = new QMVnSoft.Controls.GridControl();
            this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.txtNgay_Ps = new QMVnSoft.Controls.TextDate();
            this.lblNgay_Ps = new QMVnSoft.Controls.LabelControl();
            this.txtTen_Bp = new QMVnSoft.Controls.TextControl();
            this.txtMa_Bp = new QMVnSoft.Controls.TextSearch();
            this.lblMa_Bp = new QMVnSoft.Controls.LabelControl();
            this.lblSo_Thang = new QMVnSoft.Controls.LabelControl();
            this.txtSo_Thang = new QMVnSoft.Controls.TextNumeric();
            this.txtTen_Tk_No = new QMVnSoft.Controls.TextControl();
            this.txtTk_No = new QMVnSoft.Controls.TextSearch();
            this.lblTk_No = new QMVnSoft.Controls.LabelControl();
            ((System.ComponentModel.ISupportInitialize)(this.grdDetail)).BeginInit();
            this.SuspendLayout();
            // 
            // lblPhan_Loai
            // 
            this.lblPhan_Loai.Location = new System.Drawing.Point(12, 344);
            // 
            // txtMa_Loai1
            // 
            this.txtMa_Loai1.Location = new System.Drawing.Point(123, 341);
            this.txtMa_Loai1.TabIndex = 5;
            // 
            // txtMa_Loai2
            // 
            this.txtMa_Loai2.Location = new System.Drawing.Point(251, 341);
            this.txtMa_Loai2.TabIndex = 6;
            // 
            // txtMa_Loai3
            // 
            this.txtMa_Loai3.Location = new System.Drawing.Point(379, 341);
            this.txtMa_Loai3.TabIndex = 7;
            // 
            // grdDetail
            // 
            this.grdDetail.AllowUserToAddRows = false;
            this.grdDetail.AllowUserToDeleteRows = false;
            this.grdDetail.AllowUserToResizeRows = false;
            this.grdDetail.CheckAutoSize = true;
            this.grdDetail.CheckColor = false;
            this.grdDetail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdDetail.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Column1,
            this.Column2,
            this.Column3,
            this.Column4});
            this.grdDetail.Font = new System.Drawing.Font("Arial", 8.25F);
            this.grdDetail.Location = new System.Drawing.Point(0, 116);
            this.grdDetail.Name = "grdDetail";
            this.grdDetail.ReadOnly = true;
            this.grdDetail.Size = new System.Drawing.Size(576, 236);
            this.grdDetail.TabIndex = 4;
            this.grdDetail.CellEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.grdDetail_CellEnter);
            // 
            // Column1
            // 
            this.Column1.DataPropertyName = "Ngay_Ps";
            this.Column1.HeaderText = "Ngày";
            this.Column1.Name = "Column1";
            this.Column1.ReadOnly = true;
            this.Column1.Width = 62;
            // 
            // Column2
            // 
            this.Column2.DataPropertyName = "Ma_Bp";
            this.Column2.HeaderText = "Bộ phận";
            this.Column2.Name = "Column2";
            this.Column2.ReadOnly = true;
            this.Column2.Width = 70;
            // 
            // Column3
            // 
            this.Column3.DataPropertyName = "Ten_Bp";
            this.Column3.HeaderText = "Tên bộ phận";
            this.Column3.Name = "Column3";
            this.Column3.ReadOnly = true;
            this.Column3.Width = 301;
            // 
            // Column4
            // 
            this.Column4.DataPropertyName = "Tk_No";
            this.Column4.HeaderText = "Tài khoản";
            this.Column4.Name = "Column4";
            this.Column4.ReadOnly = true;
            this.Column4.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            // 
            // txtNgay_Ps
            // 
            this.txtNgay_Ps.DateTimeFormat  = QMVnSoft.Controls.TextDate.DateTimeFormatType.Date;
            this.txtNgay_Ps.Enabled = false;
            this.txtNgay_Ps.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtNgay_Ps.InsertKeyMode = System.Windows.Forms.InsertKeyMode.Overwrite;
            this.txtNgay_Ps.Location = new System.Drawing.Point(116, 27);
            this.txtNgay_Ps.Mask = "00/00/0000";
            this.txtNgay_Ps.Name = "txtNgay_Ps";
            this.txtNgay_Ps.OldValue = null;
            this.txtNgay_Ps.Size = new System.Drawing.Size(79, 20);
            this.txtNgay_Ps.TabIndex = 0;
            this.txtNgay_Ps.Value = ((object)(resources.GetObject("txtNgay_Ps.Value")));
            // 
            // lblNgay_Ps
            // 
            this.lblNgay_Ps.AutoSize = true;
            this.lblNgay_Ps.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblNgay_Ps.Location = new System.Drawing.Point(13, 31);
            this.lblNgay_Ps.Name = "lblNgay_Ps";
            this.lblNgay_Ps.Size = new System.Drawing.Size(79, 14);
            this.lblNgay_Ps.TabIndex = 42;
            this.lblNgay_Ps.Text = "Ngày phát sinh";
            // 
            // txtTen_Bp
            // 
            this.txtTen_Bp.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtTen_Bp.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(217)))), ((int)(((byte)(247)))));
            this.txtTen_Bp.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_Bp.CheckTextSearched = false;
            this.txtTen_Bp.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_Bp.Enabled = false;
            this.txtTen_Bp.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_Bp.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_Bp.Location = new System.Drawing.Point(222, 51);
            this.txtTen_Bp.Name = "txtTen_Bp";
            this.txtTen_Bp.OldValue = null;
            this.txtTen_Bp.Size = new System.Drawing.Size(342, 13);
            this.txtTen_Bp.TabIndex = 103;
            this.txtTen_Bp.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.None;
            this.txtTen_Bp.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_Bp.Value = ((object)(resources.GetObject("txtTen_Bp.Value")));
            // 
            // txtMa_Bp
            // 
            this.txtMa_Bp.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Bp.CheckTextSearched = false;
            this.txtMa_Bp.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_Bp.FieldDisplay = "Ten_Bp";
            this.txtMa_Bp.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Bp.Location = new System.Drawing.Point(116, 48);
            this.txtMa_Bp.MaxLength = 32;
            this.txtMa_Bp.Name = "txtMa_Bp";
            this.txtMa_Bp.OldValue = null;
            this.txtMa_Bp.ReadOnly = true;
            this.txtMa_Bp.Size = new System.Drawing.Size(100, 20);
            this.txtMa_Bp.TabIndex = 1;
            this.txtMa_Bp.TableName = "DMBP";
            this.txtMa_Bp.TextDisplay = this.txtTen_Bp;
            this.txtMa_Bp.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Bp.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Bp.Value = ((object)(resources.GetObject("txtMa_Bp.Value")));
            // 
            // lblMa_Bp
            // 
            this.lblMa_Bp.AutoSize = true;
            this.lblMa_Bp.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblMa_Bp.Location = new System.Drawing.Point(13, 52);
            this.lblMa_Bp.Name = "lblMa_Bp";
            this.lblMa_Bp.Size = new System.Drawing.Size(47, 14);
            this.lblMa_Bp.TabIndex = 102;
            this.lblMa_Bp.Text = "Bộ phận";
            // 
            // lblSo_Thang
            // 
            this.lblSo_Thang.AutoSize = true;
            this.lblSo_Thang.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblSo_Thang.Location = new System.Drawing.Point(13, 93);
            this.lblSo_Thang.Name = "lblSo_Thang";
            this.lblSo_Thang.Size = new System.Drawing.Size(97, 14);
            this.lblSo_Thang.TabIndex = 106;
            this.lblSo_Thang.Text = "Số tháng khấu hao";
            // 
            // txtSo_Thang
            // 
            this.txtSo_Thang.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtSo_Thang.Location = new System.Drawing.Point(116, 90);
            this.txtSo_Thang.Name = "txtSo_Thang";
            this.txtSo_Thang.NumericScaleOnFocus = 0;
            this.txtSo_Thang.NumericScaleOnLostFocus = 0;
            this.txtSo_Thang.NumericValue = new decimal(new int[] {
            0,
            0,
            0,
            0});
            this.txtSo_Thang.OldValue = null;
            this.txtSo_Thang.ReadOnly = true;
            this.txtSo_Thang.Size = new System.Drawing.Size(100, 20);
            this.txtSo_Thang.TabIndex = 3;
            this.txtSo_Thang.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.txtSo_Thang.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.None;
            this.txtSo_Thang.Value = ((object)(resources.GetObject("txtSo_Thang.Value")));
            // 
            // txtTen_Tk_No
            // 
            this.txtTen_Tk_No.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtTen_Tk_No.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(217)))), ((int)(((byte)(247)))));
            this.txtTen_Tk_No.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_Tk_No.CheckTextSearched = false;
            this.txtTen_Tk_No.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_Tk_No.Enabled = false;
            this.txtTen_Tk_No.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_Tk_No.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_Tk_No.Location = new System.Drawing.Point(222, 72);
            this.txtTen_Tk_No.Name = "txtTen_Tk_No";
            this.txtTen_Tk_No.OldValue = null;
            this.txtTen_Tk_No.Size = new System.Drawing.Size(342, 13);
            this.txtTen_Tk_No.TabIndex = 103;
            this.txtTen_Tk_No.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.None;
            this.txtTen_Tk_No.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_Tk_No.Value = ((object)(resources.GetObject("txtTen_Tk_No.Value")));
            // 
            // txtTk_No
            // 
            this.txtTk_No.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtTk_No.CheckTextSearched = false;
            this.txtTk_No.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtTk_No.FieldDisplay = "Ten_Tk";
            this.txtTk_No.FirstFilter = "Loai_Tk = \'C\'";
            this.txtTk_No.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTk_No.Location = new System.Drawing.Point(116, 69);
            this.txtTk_No.MaxLength = 32;
            this.txtTk_No.Name = "txtTk_No";
            this.txtTk_No.OldValue = null;
            this.txtTk_No.ReadOnly = true;
            this.txtTk_No.Size = new System.Drawing.Size(100, 20);
            this.txtTk_No.TabIndex = 2;
            this.txtTk_No.TableName = "DMTK";
            this.txtTk_No.TextDisplay = this.txtTen_Tk_No;
            this.txtTk_No.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.ItemCode;
            this.txtTk_No.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.All;
            this.txtTk_No.Value = ((object)(resources.GetObject("txtTk_No.Value")));
            // 
            // lblTk_No
            // 
            this.lblTk_No.AutoSize = true;
            this.lblTk_No.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblTk_No.Location = new System.Drawing.Point(13, 73);
            this.lblTk_No.Name = "lblTk_No";
            this.lblTk_No.Size = new System.Drawing.Size(53, 14);
            this.lblTk_No.TabIndex = 102;
            this.lblTk_No.Text = "Tài khoản";
            // 
            // FormDmTsBpEditor
            // 
            this.AddTitleText = "Thay đổi bộ phận, số tháng khấu hao, tài khoản khấu hao";
            this.ClientSize = new System.Drawing.Size(576, 375);
            this.Controls.Add(this.lblMa_Bp);
            this.Controls.Add(this.lblNgay_Ps);
            this.Controls.Add(this.grdDetail);
            this.Controls.Add(this.lblTk_No);
            this.Controls.Add(this.txtMa_Bp);
            this.Controls.Add(this.lblSo_Thang);
            this.Controls.Add(this.txtNgay_Ps);
            this.Controls.Add(this.txtTen_Bp);
            this.Controls.Add(this.txtTk_No);
            this.Controls.Add(this.txtSo_Thang);
            this.Controls.Add(this.txtTen_Tk_No);
            this.EditTitleText = "Thay đổi bộ phận, số tháng khấu hao, tài khoản khấu hao";
            this.Name = "FormDmTsBpEditor";
            this.ShowDeleteButton = true;
            this.ShowEditButton = true;
            this.Text = "Thay đổi bộ phận, số tháng khấu hao, tài khoản khấu hao";
            this.Controls.SetChildIndex(this.txtTen_Tk_No, 0);
            this.Controls.SetChildIndex(this.txtSo_Thang, 0);
            this.Controls.SetChildIndex(this.txtTk_No, 0);
            this.Controls.SetChildIndex(this.txtTen_Bp, 0);
            this.Controls.SetChildIndex(this.txtNgay_Ps, 0);
            this.Controls.SetChildIndex(this.lblSo_Thang, 0);
            this.Controls.SetChildIndex(this.txtMa_Bp, 0);
            this.Controls.SetChildIndex(this.lblTk_No, 0);
            this.Controls.SetChildIndex(this.grdDetail, 0);
            this.Controls.SetChildIndex(this.lblNgay_Ps, 0);
            this.Controls.SetChildIndex(this.lblMa_Bp, 0);
            this.Controls.SetChildIndex(this.lblPhan_Loai, 0);
            this.Controls.SetChildIndex(this.txtMa_Loai1, 0);
            this.Controls.SetChildIndex(this.txtMa_Loai2, 0);
            this.Controls.SetChildIndex(this.txtMa_Loai3, 0);
            ((System.ComponentModel.ISupportInitialize)(this.grdDetail)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        protected override void OnAdd()
        {
            base.OnAdd();
            this.txtNgay_Ps.Focus();
            this.oDetailRow = base.LocalTable.NewRow();
            this.oDetailRow["Stt2"] = AppDataAccess.Cong_So_Tt(AppInstance.Subsidiary);
            this.oDetailRow["Ngay_Ps"] = DateTime.Today;
            this.txtNgay_Ps.Value = DateTime.Today;
        }

        protected override void OnDelete()
        {
            if (MessageBox.Show(AppInstance.DeleMessage, AppInstance.SoftwareName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                this.ii_RowIndex = -1;
                this.oMethod.DeleteDetailRow2(base.LocalCurrentRow["Stt"], this.oDetailRow["Stt2"]);
                base.LocalTable.Rows.Remove(this.oDetailRow);
            }
        }

        protected override void OnEdit()
        {
            base.OnEdit();
            this.txtNgay_Ps.Focus();
        }

        protected override void OnReset()
        {
            base.LocalTable = this.oMethod.GetDetailTable2(base.LocalCurrentRow["Stt"]);
            this.grdDetail.DataSource = new BindingSource(base.LocalTable, base.LocalTable.TableName);
            base.OnReset();
        }

        protected override void OnResetStatus(bool pb_Status)
        {
            this.txtNgay_Ps.Enabled = !pb_Status;
            this.txtMa_Bp.ReadOnly = pb_Status;
            this.txtTk_No.ReadOnly = pb_Status;
            this.txtSo_Thang.ReadOnly = pb_Status;
            this.grdDetail.Enabled = pb_Status;
            base.OnResetStatus(pb_Status);
        }

        public override bool OnSave()
        {
            if (this.oDetailRow != null)
            {
                this.oDetailRow["Ngay_Ps"] = this.txtNgay_Ps.Value;
                this.oDetailRow["Ma_Bp"] = this.txtMa_Bp.Value;
                this.oDetailRow["Ten_Bp"] = this.txtTen_Bp.Value;
                this.oDetailRow["Tk_No"] = this.txtTk_No.Value;
                this.oDetailRow["Ten_Tk_No"] = this.txtTen_Tk_No.Value;
                this.oDetailRow["So_Thang"] = this.txtSo_Thang.Value;
            }
            if (base.NewChecked)
            {
                base.LocalTable.Rows.Add(this.oDetailRow);
                BindingSource dataSource = this.grdDetail.DataSource as BindingSource;
                dataSource.Position = dataSource.Find("Stt2", this.oDetailRow["Stt2"]);
            }
            this.oMethod.SaveDetailRow2(base.LocalCurrentRow["Stt"], this.oDetailRow);
            return base.OnSave();
        }

        private void OnShowObjects()
        {
            this.txtNgay_Ps.Value = this.oDetailRow["Ngay_Ps"];
            this.txtMa_Bp.Value = this.oDetailRow["Ma_Bp"];
            this.txtTen_Bp.Value = this.oDetailRow["Ten_Bp"];
            this.txtTk_No.Value = this.oDetailRow["Tk_No"];
            this.txtTen_Tk_No.Value = this.oDetailRow["Ten_Tk_No"];
            this.txtSo_Thang.Value = this.oDetailRow["So_Thang"];
        }
    }
}

